import StorageKeys from '@/common/const/StorageKeys'
let RED_CLOUD_UNION = ''
let BANNER_AND_VIDEO = ''
let PLAY_BROADCAST = '' //当前播报的活动id
try {
  BANNER_AND_VIDEO = localStorage.getItem(StorageKeys.BANNER_AND_VIDEO)
  RED_CLOUD_UNION = localStorage.getItem(StorageKeys.RED_CLOUD_UNION)
  PLAY_BROADCAST = localStorage.getItem(StorageKeys.PLAY_BROADCAST)
} catch (e) {
  console.debug(e)
}
const AppStore = {
  state: {
    footerBarIndex: 0,
    homeSearchKeywords: '',
    BANNER_AND_VIDEO: BANNER_AND_VIDEO ||  '',
    RED_CLOUD_UNION: RED_CLOUD_UNION ||  '',
    count:0,
    oneAnswerHints:true,
    userWarningFlag:true,//初始化首页是否弹出用户状态
    cachePages:['home','redfriendscircle'],
    PLAY_BROADCAST: PLAY_BROADCAST || '',//当前播报的活动id
  },
  mutations: {
    setHomeSearchKeywords (state, keywords) {
      state.homeSearchKeywords = keywords
    },
    setBANNER_AND_VIDEO (state, key) {
      state[StorageKeys.BANNER_AND_VIDEO] = key
      localStorage.setItem(StorageKeys.BANNER_AND_VIDEO, key)
    },
    setPLAY_BROADCAST (state, key) {
      state[StorageKeys.PLAY_BROADCAST] = key
      localStorage.setItem(StorageKeys.PLAY_BROADCAST, key)
    },
    setRED_CLOUD_UNION (state, key) {
      state[StorageKeys.RED_CLOUD_UNION] = key
      localStorage.setItem(StorageKeys.RED_CLOUD_UNION, key)
    },
    updateCount(state, key){
      state.count = key
    },
    addRoute(state, name) {
      let index = state.cachePages.indexOf(name)
      if(index < 0) {
        state.cachePages.push(name)
      }
    },
    removeRoute(state, name) {
      let index = state.cachePages.indexOf(name)
      if(index >= 0) {
        state.cachePages.splice(index, 1)
      }
    }
  },
  actions: {
  },
  getters: {
  }
}

export default AppStore
